<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <input v-model="age"/>
        <input v-model="firstName"/>
        <input v-model="lastName"/>
        <p>你的全名叫:{{fullNameInComputed}}</p>
        <p>你的全名叫:{{fullNameInMethods()}}</p>
    </div>
    <script src="https://unpkg.com/vue@2.6.14/dist/vue.js"></script>
    <script>
        //计算属性可以用来处理数据变化时的监听处理
        //1.可能封装部分逻辑计算 2.提高性别，计算属性会进行缓存，，在更新的时候，只要依赖项不变就不需要重新计算
        var vm = new Vue({
            el:'#app',
            data:()=>{
                return {
                    firstName:'',
                    lastName:'',
                    age:0
                }
            },
            methods:{
                fullNameInMethods(){
                    console.log('fullNameInMethods')
                    return this.firstName+this.lastName;
                }
            },
            computed:{
              /*   fullNameInComputed(){
                    console.log('fullNameInComputed')
                    return this.firstName+this.lastName;
                } */
                fullNameInComputed:{
                    get(){
                        return this.firstName+' '+this.lastName;
                    },
                    set(newValue){
                        let [firstName,lastName] = newValue.split(' ');
                        this.firstName = firstName;
                        this.lastName=lastName;

                    }
                }
            }
        });
    </script>
</body>
</html>